package com.controller;


import com.alibaba.fastjson.JSON;
import com.domain.*;
import com.webservice.*;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;

@Controller
@RequestMapping("/reviewer")
public class
ReviewerController {

    @Resource
    private UserWebservice userWebservice;

    @Resource
    private OrderWebservice orderWebservice;

    @Resource
    private EquipmentWebservice equipmentWebservice;

    @Resource
    private BiddingWebservice biddingWebservice;

    @Resource
    private ProcessWebservice processWebservice;
    @Resource
    private StatisticsWebService statisticsWebService;

    @RequestMapping("/reviewerOrder")
    public String approvePriceList(Model model, HttpServletRequest request){
        return "reviewer/reviewerOrder";
    }

    @RequestMapping("/reviewerChoice")
    public String reviewerChoice(@RequestBody Map<String,String> map){
        return "redirect:/reviewer/reviewerOrder";
    }

    @RequestMapping("/personManage")
    public String reviewpersonManage(Model model, HttpServletRequest request){
        HttpSession session = request.getSession();
        User reviewer = (User) session.getAttribute("user");
        model.addAttribute("reviewer", reviewer);
        List<User> inside = new ArrayList<User>();
        List<User> users = userWebservice.findUserByState(2);
        int number1=0 ,number2=0,number3=0;
        if (users!=null){
            for(User user : users){
                if(user.getRole_id()>1) {
                    inside.add(user);
                    if(user.getRole_id()==2)
                        number1++;
                    if(user.getRole_id()==3)
                        number2++;
                    if(user.getRole_id()==4)
                        number3++;
                }
            }
        }
        model.addAttribute("number1",number1);
        model.addAttribute("number2",number2);
        model.addAttribute("number3",number3);
        model.addAttribute("users",inside);
        return "reviewer/personManage";
    }

    @RequestMapping("/equipmentManage")
    public String reviewequipmentManage(Model model, HttpServletRequest request){
        HttpSession session = request.getSession();
        User reviewer = (User) session.getAttribute("user");
        model.addAttribute("reviewer", reviewer);
        List<Equipment> list = equipmentWebservice.findAllEquipment();
        model.addAttribute("lists",list);

        return "reviewer/equipmentManage";

    }

    @RequestMapping("/allOrderinfo")
    public String reviewallOrder(String time,Model model, HttpServletRequest request){
        HttpSession session = request.getSession();
        User reviewer = (User) session.getAttribute("user");
        model.addAttribute("reviewer", reviewer);
        float sum = 0;
        if (time != null) {
            List<Maintenance_order> maintenance_orders = new ArrayList<Maintenance_order>();
            maintenance_orders = orderWebservice.findAllOrderByTime(time);
            if(maintenance_orders!=null) {
                for (Maintenance_order orders : maintenance_orders) {
                    sum = sum + orders.getFinal_price();
                }
                model.addAttribute("number", maintenance_orders.size());
            }else{
                    model.addAttribute("number", 0);
                }

                model.addAttribute("price", sum);
                model.addAttribute("orderlist", maintenance_orders);
            } else {
                List<Maintenance_order> maintenance_orders = new ArrayList<Maintenance_order>();
                Date date = new Date(System.currentTimeMillis());
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
                time = sdf.format(date);
                maintenance_orders = orderWebservice.findAllOrderByTime(time);
                if (maintenance_orders!=null) {
                    for (Maintenance_order orders : maintenance_orders) {
                        sum = sum + orders.getFinal_price();
                    }
                    model.addAttribute("number", maintenance_orders.size());
                }else{
                    model.addAttribute("number", 0);
                }
                model.addAttribute("price", sum);
                model.addAttribute("orderlist", maintenance_orders);
            }
        model.addAttribute("time",time);

        return "reviewer/allOrderinfo";
    }

    /**
     * *根据维修单来找相关所有的维修单详情
     * @param model
     * @param request
     * @return
     */
    @RequestMapping("/orderdetails")
    public String orderdetails(Integer equipment_id,Model model, HttpServletRequest request){
        HttpSession session = request.getSession();
        User reviewer = (User) session.getAttribute("user");
        model.addAttribute("reviewer", reviewer);
        List<Maintenance_order> maintenance_orders = new ArrayList<Maintenance_order>();
        Equipment equipment = equipmentWebservice.findById(equipment_id);
        if(orderWebservice.findHOrderByEquipment(equipment_id)!=null){
            maintenance_orders = orderWebservice.findHOrderByEquipment(equipment_id);
        }
        model.addAttribute("orders",maintenance_orders);
        model.addAttribute("equ_name",equipment);
        return "reviewer/orderdetails";
    }
    /**
     * *维修单审批(公司参与竞标的维修单)reviewerpass
     * @param model
     * @param request
     * @return
     */
    @RequestMapping("/orderView")
    public String orderView(Model model, HttpServletRequest request){
        HttpSession session = request.getSession();
        User reviewer = (User) session.getAttribute("user");
        model.addAttribute("reviewer", reviewer);
        Bidding bidding;
        Map<Maintenance_order,Bidding> map = new HashMap<>();
        List<Maintenance_order> list = new ArrayList<Maintenance_order>();
     //   List<Maintenance_order> maintenance_orders = processWebservice.findTask(reviewer.getId());
        List<Maintenance_order> orders = processWebservice.findTask(reviewer.getId());
        if(orders!=null) {
            for (Maintenance_order m_order : orders) {
                    list.add(m_order);
            }
        }
        model.addAttribute("orders",list);
       // model.addAttribute("orders",map);
        return "reviewer/orderView";
    }
    /**
     * *验收审批
     * @param model
     * @param request
     * @return
     */
    @RequestMapping("/completeView")
    public String completeView(Model model, HttpServletRequest request){
        HttpSession session = request.getSession();
        User reviewer = (User) session.getAttribute("user");
        model.addAttribute("reviewer", reviewer);
        List<Maintenance_order> orderlist = new ArrayList<Maintenance_order>();
        List<Maintenance_order> maintenance_orders = processWebservice.findTask(reviewer.getId());
        if(maintenance_orders!=null) {
            for (Maintenance_order m_order : maintenance_orders) {
                if (m_order.getOrder_state() == 7) {
                    orderlist.add(m_order);
                }
            }
        }
        model.addAttribute("orders",orderlist);
        return "reviewer/completeView";
    }

    /**
     * *维修单审批(公司参与竞标的维修单)reviewerpass
     * @param model //这里的通过和驳回是一个方法
     * @param request
     * @return
     */
    @RequestMapping("/reviewerpass")
    @ResponseBody
    public String reviewerpass(@RequestBody Map<String,String> map,Model model, HttpServletRequest request){
        HttpSession session = request.getSession();
        User reviewer = (User) session.getAttribute("user");
        model.addAttribute("reviewer", reviewer);
        Integer order_id = Integer.valueOf(map.get("orderId"));
        int i = processWebservice.review_Pass(order_id,reviewer.getId(),"");
        return  "redirect:/reviewer/orderView";
    }
    /**
     * *维修单审批(公司参与竞标的维修单)竞单驳回
     * @param model
     * @param request
     * @return
     */
    @RequestMapping("/reviewerreject")
    @ResponseBody
    public String reviewerreject(@RequestBody Map<String,String> map,Model model, HttpServletRequest request){
        HttpSession session = request.getSession();
        User reviewer = (User) session.getAttribute("user");
        model.addAttribute("reviewer", reviewer);
        Integer order_id = Integer.valueOf(map.get("orderId"));
        String reason = map.get("reason");
        int i = processWebservice.reviewer_Refuse(order_id,reviewer.getId(),"");
        return  "redirect:/reviewer/orderView";
    }
    /**
     * *维修单验收审批（同意）
     * @param model
     * @param request
     * @return
     */
    @RequestMapping("/revieweRagree")
    @ResponseBody
    public String revieweRagree(@RequestBody Map<String,String> map,Model model, HttpServletRequest request){
        HttpSession session = request.getSession();
        User reviewer = (User) session.getAttribute("user");
        model.addAttribute("reviewer", reviewer);
        Integer order_id = Integer.valueOf(map.get("orderId"));
        int i = processWebservice.reviewer_Refuse(order_id,reviewer.getId(),"");
        return  "redirect:/reviewer/completeView";
    }
    /**
     * *维修单验收审批（拒绝）
     * @param model
     * @param request
     * @return
     */
    @RequestMapping("/reviewerDisagree")
    @ResponseBody
    public String reviewerDisagree(@RequestBody Map<String,String> map,Model model, HttpServletRequest request){
        HttpSession session = request.getSession();
        User reviewer = (User) session.getAttribute("user");
        model.addAttribute("reviewer", reviewer);
        Integer order_id = Integer.valueOf(map.get("orderId"));
        String reason = map.get("reason");
        int i = processWebservice.reviewer_Refuse(order_id,reviewer.getId(),reason);
        return  "redirect:/reviewer/completeView";
    }

    /**
     * 查找维修单
     * @param
     * @return
     */
    @RequestMapping("/findOrder")
    @ResponseBody
    public Maintenance_order findOrder( @RequestBody Map<String,String> map){
        Integer orderid = Integer.valueOf(map.get("id"));
        Maintenance_order maintenance_order = orderWebservice.findOne(orderid);
        return maintenance_order;
    }
    /**
     * 通过设备id查找设备的详情信息
     * @param
     * @param
     * @return
     */
    @RequestMapping("/findEquipment")
    @ResponseBody
    public Equipment findEquipment(@RequestBody Map<String,String> map,Model model, HttpServletRequest request){
        HttpSession session = request.getSession();
        User reviewer = (User) session.getAttribute("user");
        List<String> strings1 = new ArrayList<>();

        model.addAttribute("reviewer", reviewer);
        Integer equ_id  = Integer.valueOf(map.get("id"));
        Equipment equipment = equipmentWebservice.findById(equ_id);
        return  equipment;
    }
    /**
     * *维修单验收详情页面
     * @param model
     * @param request
     * @return
     */
    @RequestMapping("/review_receive")

    public String review_receive(Integer id,Model model, HttpServletRequest request){
        HttpSession session = request.getSession();
        User reviewer = (User) session.getAttribute("user");
        model.addAttribute("reviewer", reviewer);

        String a="";
        String b="";
        List<Maintenance_request> requests = new ArrayList<>();
        requests = orderWebservice.findAllRequest(id);

        Maintenance_order maintenance_order = orderWebservice.findOne(id);
        model.addAttribute("order",maintenance_order);
        String photoes = maintenance_order.getSolution_image();
        List<String> map = new ArrayList<>();
//        System.out.println(photoes);
        if(photoes!=null){
            String[] strings = photoes.split(",");
            if (strings!=null){
                for (String str:strings){
                    if (str!=null && !str.equals("")){
                        map.add(str);
                    }
                }
            }
            model.addAttribute("photoes",map);
        }
        if(requests!=null) {
            for (Maintenance_request request1 : requests) {
                if (request1.getRole_id() == 2) {
                    a = request1.getMaintenance_request();//这是设备管理员的要求
//                    System.out.println(a);
                }
                if (request1.getRole_id() == 3) {
                    b = request1.getMaintenance_request();
//                    System.out.println(b);
                }
            }
        }
        model.addAttribute("a",a);
        model.addAttribute("b",b);

        return  "/reviewer/review_receive";
    }

    /**
     * *审批员的审批信息
     * @param model
     * @param request
     * @return
     */
    @RequestMapping("/detail_review")
    public String detail_review(Integer id,Integer company_id,Model model, HttpServletRequest request){
        HttpSession session = request.getSession();
        User reviewer = (User) session.getAttribute("user");
        model.addAttribute("reviewer", reviewer);
        String a = "";
        String b = "";
        String c = "";
        String d = "";
        String e = "";
        String f = "";
        Maintenance_order maintenance_order = orderWebservice.findOne(id);
        if(maintenance_order.getOrder_state() == 12 ) {
            Bidding bid = biddingWebservice.findBiddingByCompany(id, company_id);
            model.addAttribute("bid",bid);
        }
        String photoes = maintenance_order.getProblem_image();
        List<String> map = new ArrayList<>();
//        System.out.println(photoes);

        List<String> problem_video = new ArrayList<>();
        List<String> slove_video = new ArrayList<>();
        List<String> slove_image = new ArrayList<>();
        String video = maintenance_order.getProblem_video();
        String videos = maintenance_order.getSolution_video();
        String photos = maintenance_order.getSolution_image();
        List<Maintenance_request> requests = new ArrayList<>();
        requests = orderWebservice.findAllRequest(id);
        if(videos!=null){
            String[] strs2 = videos.split(",");
            if(strs2!=null){
                for (String str:strs2){
                    if (str!=null && !str.equals("")){
                        slove_video.add(str);
                    }
                }

            }
            model.addAttribute("videos",slove_video);
        }

        if(photos!=null){
            String[] strs3 = photos.split(",");
            if(strs3!=null){
                for (String str:strs3){
                    if (str!=null && !str.equals("")){
                        slove_image.add(str);
                    }
                }

            }
            model.addAttribute("photos",slove_image);
        }



        if(video!=null){
            String[] strs = video.split(",");
            if(strs!=null){
                for (String str:strs){
                    if (str!=null && !str.equals("")){
                        problem_video.add(str);
                    }
                }

            }
            model.addAttribute("video",problem_video);
        }

        if(photoes!=null){
            String[] strings = photoes.split(",");
            for (String str:strings){
                if (str!=null && !str.equals("")){
                    map.add(str);
                }
            }
            model.addAttribute("photoes",map);
        }
        if(requests!=null) {
            for (Maintenance_request request1 : requests) {
                if (request1.getRole_id() == 2) {
                    a = request1.getMaintenance_request();//这是设备管理员的要求
//                    System.out.println(a);
                }
                if (request1.getRole_id() == 3) {
                    if(request1.getUser_name().equals(maintenance_order.getEquipment_admin_name())){
                        f=request1.getMaintenance_request();
//                        System.out.println("设备管理员："+f);
                    }else{
                        b = request1.getMaintenance_request();
                    }
//                    System.out.println("审核员："+b);
                }
                if (request1.getRole_id() == 4) {
                    c = request1.getMaintenance_request();
//                    System.out.println("处级审批员："+c);
                }
            }
        }
        model.addAttribute("a",a);
        model.addAttribute("b",b);
        model.addAttribute("c",c);
        model.addAttribute("f",f);
        model.addAttribute("order",maintenance_order);
        return "reviewer/detail_review";
    }
    //审批员审批审核员的保修
    @RequestMapping("/receive_ok")
    public int receive_ok(@RequestBody Map<String,String> map, Model model, HttpServletRequest request, HttpServletResponse response)throws IOException
    {
        HttpSession session = request.getSession();
        User reviewer = (User) session.getAttribute("user");
        model.addAttribute("reviewer", reviewer);

        int i = processWebservice.first_review(Integer.valueOf(map.get("id")),reviewer.getId(),"","");
        return i;
    }
    //审批员审批审核员的不同意报修
    @RequestMapping("/receive_no")
    @ResponseBody
    public int receive_no(@RequestBody Map<String,String> map, Model model, HttpServletRequest request, HttpServletResponse response)throws IOException
    {
        HttpSession session = request.getSession();
        User reviewer = (User) session.getAttribute("user");
        model.addAttribute("reviewer", reviewer);
        int i = processWebservice.first_review(Integer.valueOf(map.get("id")),reviewer.getId(),"",map.get("reason2"));
//        System.out.println(i);
        return i;
    }
    //审批员验收同意审批
    @RequestMapping("/reviewer_ok")
    @ResponseBody
    public int reviewer_ok(@RequestBody Map<String,String> map,Model model, HttpServletRequest request, HttpServletResponse response)throws IOException
    {
        HttpSession session = request.getSession();
        User reviewer = (User) session.getAttribute("user");
        model.addAttribute("reviewer", reviewer);
        int i = processWebservice.reviewer_Refuse(Integer.valueOf(map.get("id")),reviewer.getId(),"");
//        System.out.println("****i"+i);
        return i;
    }

    //审批员验收拒绝审批
    @RequestMapping("/reviewer_no")
    @ResponseBody
    public int reviewer_no(String id, String reason, Model model, HttpServletRequest request, HttpServletResponse response)throws IOException
    {
        HttpSession session = request.getSession();
        User reviewer = (User) session.getAttribute("user");
        model.addAttribute("reviewer", reviewer);
        int i = processWebservice.reviewer_Refuse(Integer.valueOf(id),reviewer.getId(),reason);
//        System.out.println(i);
        return i;
    }

    //审批员竞单审批同意
    @RequestMapping("/bid_ok")
    public int bid_ok(@RequestBody Map<String,String> map,Model model, HttpServletRequest request, HttpServletResponse response)throws IOException
    {
        HttpSession session = request.getSession();
        User reviewer = (User) session.getAttribute("user");
        model.addAttribute("reviewer", reviewer);
        int i = processWebservice.review_Pass(Integer.valueOf(map.get("id")),reviewer.getId(),"");
//        System.out.println(i);
        return i;
    }

    //审批员竞单审批不同意
    @RequestMapping("/bid_no")
    public int bid_no(@RequestBody Map<String,String> map ,Model model, HttpServletRequest request, HttpServletResponse response)throws IOException
    {
        HttpSession session = request.getSession();
        User reviewer = (User) session.getAttribute("user");
        model.addAttribute("reviewer", reviewer);
        int i = processWebservice.review_Pass(Integer.valueOf(map.get("id")),reviewer.getId(),map.get("reason"));
//        System.out.println(i);
        return i;
    }
    @RequestMapping("/equip_statis")
    public String equip_statis(String times,HttpServletRequest request, Model model) {
        HttpSession session = request.getSession();
        User admin = (User) session.getAttribute("user");
        model.addAttribute("admin", admin);
        Date time = new Date();
        int d1=0,d2=0,d3=0;//n完成m异常b正在进行
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String date = formatter.format(time);
        String year = date.substring(0,4);
        if(times!=null){
            year = times;
        }
        List<Map<String, Object>> lm = new ArrayList<>();
        List<Integer> lm2 = new ArrayList<>();
        List<Integer> lm3 = new ArrayList<>();
        List<Integer> lm4 = new ArrayList<>();
        int dates = Integer.parseInt(year);
        Map<String, Object> map = new HashMap<>();
        List<Integer> dt = new ArrayList<>();
        for(int i = dates-5;i<=dates;i++){
            map = JSON.parseObject(statisticsWebService.maintenancePriceAndTimes(String.valueOf(i)));
            //营房
            d1 = statisticsWebService.maintenanceTimesOfEquipmentYear(3,String.valueOf(i));
            //装备
            d2 = statisticsWebService.maintenanceTimesOfEquipYear(String.valueOf(i));
            //公共
            d3 = statisticsWebService.maintenanceTimesOfEquipmentYear(6,String.valueOf(i));
            lm.add(map);
            lm2.add(d1);
            lm3.add(d2);
            lm4.add(d3);
            dt.add(i);
        }
        model.addAttribute("house",lm2);
        model.addAttribute("equip",lm3);
        model.addAttribute("public1",lm4);
        model.addAttribute("dt",dt);
        model.addAttribute("list",lm);
        model.addAttribute("year",year);
        model.addAttribute("map",map);
        return "reviewer/equip_statis";
    }
    @RequestMapping("/orderstatis")
    public String orderstatis(String times,HttpServletRequest request, Model model) {
        HttpSession session = request.getSession();
        User admin = (User) session.getAttribute("user");
        model.addAttribute("admin", admin);
        Date time = new Date();
        int n =0,m = 0,b=0 ,id;//n完成m异常b正在进行
        float company=0.0f,people=0.0f;
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String date = formatter.format(time);
        String year = date.substring(0,4);
//        System.out.println(year);
        List<Integer> list1 = new ArrayList<>();
        List<Integer> list2 = new ArrayList<>();
        List<Integer> list3 = new ArrayList<>();
        List<Float> list4 = new ArrayList<>();
        List<Float> list5 = new ArrayList<>();
        if(times!=null) {
            year = times;
        }
        for (int i = 1; i <= 12; i++) {
            List<Maintenance_order> list = new ArrayList<>();
            list = orderWebservice.findAllOrderByTime(year + "-" + i);
            if (list != null) {
                n = 0;
                m = 0;
                b = 0;
                company = 0;
                people = 0;
                for (Maintenance_order maintenance_order : list) {
                    if (maintenance_order.getUnit_id() != null) {
                        id = maintenance_order.getUnit_id();
                        User user = userWebservice.findById(id);
                        if (user != null) {
                            if (user.getRole_id() == -1) {
                                company = company + maintenance_order.getFinal_price();
                            }
                            if (user.getRole_id() == -2) {
                                people = people + maintenance_order.getFinal_price();
                            }
                        }
                    }
                    if (maintenance_order.getOrder_state() == 10) {
                        n++;
                    } else if (maintenance_order.getOrder_state() == 11) {
                        m++;
                    } else {
                        b++;
                    }
                }
                list1.add(n);
                list2.add(m);
                list3.add(b);
                list4.add(company);
                list5.add(people);
            } else {
                list1.add(0);
                list2.add(0);
                list3.add(0);
                list4.add(Float.valueOf("0"));
                list5.add(Float.valueOf("0"));
            }
        }
        model.addAttribute("list1", list1);
        model.addAttribute("list2", list2);
        model.addAttribute("list3", list3);
        model.addAttribute("list4", list4);
        model.addAttribute("list5", list5);

        List<Integer> list_1 = new ArrayList<>();
        List<Integer> list_2 = new ArrayList<>();
        List<Integer> list_3 = new ArrayList<>();
        for (int i = 1; i <= 12; i++) {
            List<Maintenance_order> maintenance_orders1 = orderWebservice.findAll(year + "-" + i, 1);//营房
            List<Maintenance_order> maintenance_orders2 = orderWebservice.findAll(year + "-" + i, 2);//装备
            List<Maintenance_order> maintenance_orders3 = orderWebservice.findAll(year + "-" + i, 3);//公共
            if (maintenance_orders1 != null) {
                list_1.add(maintenance_orders1.size());
            } else {
                list_1.add(0);
            }

            if (maintenance_orders2 != null) {
                list_2.add(maintenance_orders2.size());
            } else {
                list_2.add(0);
            }

            if (maintenance_orders3 != null) {
                list_3.add(maintenance_orders3.size());
            } else {
                list_3.add(0);
            }
        }
        model.addAttribute("list_1", list_1);
        model.addAttribute("list_2", list_2);
        model.addAttribute("list_3", list_3);

        model.addAttribute("year",year);
        return "reviewer/orderstatis";
    }
    @RequestMapping("/peoplestatis")
    public String peoplestatis(String times,HttpServletRequest request, Model model) {
        HttpSession session = request.getSession();
        User admin = (User) session.getAttribute("user");
        model.addAttribute("admin", admin);
        Date time = new Date();
        int n =0,m = 0,b=0 ,id;//n完成m异常b正在进行
        float company=0.0f,people=0.0f;
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String date = formatter.format(time);
        String year = date.substring(0,4);
        List<User> userList = userWebservice.findUserByState(2);
        int q=0,w=0,e=0,r=0,t=0;
        if(times!=null){
            year = times;
        }
        Map<String, Object> map = new HashMap<>();

        Map<String, Object> map2 = new HashMap<>();
        int dates = Integer.parseInt(year);
        List<Integer> dt = new ArrayList<>();
        List<Map<String, Object>> lm1 = new ArrayList<>();
        List<Map<String, Object>> lm2 = new ArrayList<>();
        for(int i = dates-5;i<=dates;i++){
            //公司
            map = JSON.parseObject(statisticsWebService.maintenancePriceOfMaintenanceUnitYear(String.valueOf(i)));
            lm1.add(map);
            //个人

            dt.add(i);
        }
        model.addAttribute("dt",dt);
        model.addAttribute("map",lm1);

        if (userList != null) {
            for(User user:userList){
                if(user.getRole_id()==-1){
                    q++;
                }else if(user.getRole_id()==-2){
                    w++;
                }else if(user.getRole_id()==2){
                    e++;
                }else if(user.getRole_id()==3){
                    r++;
                }else if(user.getRole_id()==4){
                    t++;
                }
            }
        }
        model.addAttribute("q",q);
        model.addAttribute("w",w);
        model.addAttribute("e",e);
        model.addAttribute("r",r);
        model.addAttribute("t",t);
        List<Float> list4 = new ArrayList<>();
        List<Float> list5 = new ArrayList<>();
        for(int i = 1;i<=12;i++) {
            List<Maintenance_order> list = new ArrayList<>();
            list = orderWebservice.findAllOrderByTime(year+"-"+i);
            if(list!=null) {
                n=0;
                m=0;
                b=0;
                company=0;
                people=0;
                for(Maintenance_order maintenance_order:list){
                    if(maintenance_order.getUnit_id()!=null) {
                        id = maintenance_order.getUnit_id();
                        User user = userWebservice.findById(id);
                        if (user != null) {
                            if (user.getRole_id() == -1) {
                                company=company+maintenance_order.getFinal_price();
                            }
                            if (user.getRole_id() == -2) {
                                people=people+maintenance_order.getFinal_price();
                            }
                        }
                    }
                    if(maintenance_order.getOrder_state()==10){
                        n++;
                    }else if(maintenance_order.getOrder_state()==11){
                        m++;
                    }else{
                        b++;
                    }
                }
                list4.add(company);
                list5.add(people);
            }else{
                list4.add(Float.valueOf("0"));
                list5.add(Float.valueOf("0"));
            }
        }
        model.addAttribute("list4",list4);
        model.addAttribute("list5",list5);
        model.addAttribute("year",year);
        return "reviewer/peoplestatis";
    }
}
